# Maintainer: Dominic Sisneros <dsisnero@gmail.com>

_realname=mruby
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.2.0
pkgrel=1
pkgdesc="mruby is the lightweight implementation of the Ruby language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/mruby"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-ruby"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "bison")
source=(${_realname}-${pkgver}.zip::"https://github.com/${_realname}/${_realname}/archive/${pkgver}.zip")
sha256sums=('64a0dd8b65825f2e7cdac6699e818648dc73bfdfc68aa1bfd58417a35315e5cc')

prepare() {
  cd  "${srcdir}/${_realname}-${pkgver}"

}

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  cp -rf "${srcdir}/${_realname}-${pkgver}" ${srcdir}/build-${MSYSTEM}
  cd ${srcdir}/build-${MSYSTEM}
  # touch to ensure bison is regenerated, to ensure it's working
  touch mrbgems/mruby-compiler/core/parse.y

  ./minirake -v
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  install -d "${pkgdir}${MINGW_PREFIX}"/bin

  # In build_config\default.rb file, enable_debug option is disabled for performance
  # https://github.com/mruby/mruby/commit/3c55cb089514d40ff17e9f29f9195c85111e0c10
  # cp build/host-debug/bin/* "${pkgdir}${MINGW_PREFIX}"/bin/ || return 1

  cp build/host/bin/* "${pkgdir}${MINGW_PREFIX}"/bin/ || return 1

  install -d "${pkgdir}${MINGW_PREFIX}"/lib
  cp build/host/lib/*.a "${pkgdir}${MINGW_PREFIX}"/lib/

  install -d "${pkgdir}${MINGW_PREFIX}"/include
  cp -r include/* "${pkgdir}${MINGW_PREFIX}"/include/
}
